﻿namespace EyeOpen.Web.Mvc
{
	using System;
	using System.Linq.Expressions;
	using System.Web.Mvc;
	using System.Web.Mvc.Ajax;
	using System.Web.Mvc.Html;

	public static class AjaxHelperExtensions
	{
		public static MvcForm BeginForm<TController>(
			this AjaxHelper ajaxHelper, 
			Expression<Action<TController>> action, 
			AjaxOptions ajaxOptions)
			where TController : Controller
		{
			var controllerName = typeof(TController).Name.Replace("Controller", null);

			var actionName = TypeExtensions.GetMethodName(action);

			return
				ajaxHelper
					.BeginForm(actionName, controllerName, ajaxOptions);
		}
	}
}